<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/icon.css" />
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css" />
<script type="text/javascript" src="js/common.js"></script>
<title>回款记录</title>
</head>
<body>
	<style type="text/css">
.step {
	margin-top: 20px;
}
</style>
	<script type="text/javascript">
		$(function() {
			$("#zj-back-record-all-dg")
					.datagrid(
							{
								url : 'getAllBackRecord',
								toolbar : '#zj-back-record-tb',
								fit : true,
								border : false,
								pageSize : 9,
								pageList : [5,8,9,10,15,20],
								fitColumns : true,
								method : 'get',
								singleSelect : false,
								pagination : true,
								columns : [ [
										{
											field : 'backRE',
											width : 1,
											checkbox : true
										},
										{
											field : 'brId',
											title : 'ID',
											width : 1,
										},
										{
											field : 'brTime',
											title : '回款日期',
											width : 1,
											formatter : function(value, row,
													index) {
												if (value) {
													var date = new Date(value);
													var y = date.getFullYear();
													var m = date.getMonth() + 1;
													var d = date.getDate();
													return y + '-' + m + '-'
															+ d;
												}
											}
										},
										{
											field : 'brCoName',
											title : '客户',
											width : 1,
											formatter : function(value, row,
													index) {
												return value
														+ '<a class="zj-back-record-zj-cus" onclick="zj_go_to_cus_info('
														+ row.coCusId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
											}
										},
										{
											field : 'coThemeVo',
											title : '合同/订单',
											width : 1,
										},
										{
											field : 'brMoney',
											title : '金额',
											width : 1,
										},
										{
											field : 'brPeriod',
											title : '期次',
											width : 1,
										},
										{
											field : 'brPayWay',
											title : '付款方式',
											width : 1,
										},
										{
											field : 'brOwner',
											title : '所有者',
											width : 1,
										},
										{
											field : 'brIfTicket',
											title : '已开发票',
											width : 1,
										},
										{
											field : 'sgycaozuo',
											title : '操作',
											width : 2,
											formatter : function(value, row,
													index) {
												var editBackRecord = '<a class="zj-back-record-edit" onclick="editBackRecord('
														+ row.brId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var deleteBackRecord = '<a class="zj-back-record-delete" onclick="deleteBackRecord('
														+ row.brId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												return editBackRecord
														+ deleteBackRecord;
											}
										} ] ],
								onLoadSuccess : function(data) {
									$('.zj-back-record-delete').linkbutton({
										text : '删除',
										plain : true,
										iconCls : 'icon-cut'
									});
									$('.zj-back-record-edit').linkbutton({
										text : '编辑',
										plain : true,
										iconCls : 'icon-edit'
									});
								},
								rowStyler : function(index, row) {
									return 'height:30px';
								}
							});

			$("#zj_back_record_list_all").linkbutton({
				onClick : function() {
					$("#zj-back-record-all-dg").datagrid({
						pageNumber : 1,
						url : 'getAllBackRecord'
					});
					$("#zj-back-record-all-dg").datagrid("reload");
				}
			});

			$("#zj_btn_back_record_add").linkbutton({
				onClick : function() {
					$("#zj-back-record-dialog").dialog({
						title : '新建回款记录'
					});
					$("#zj-back-record-add-form").form("clear");
					$("#zj-back-record-form-cus").textbox({readonly:false})
					$("#zj-back-record-dialog").dialog("open");
				}
			});

			$("#zj-back-recor-brid").textbox({
				onChange : function() {
					var coId = $(this).textbox('getValue');
					$('#zj-input-back-record-order').combobox({
						url : 'getOrdersById?coId=' + coId,
						valueField : 'coId',
						textField : 'coTheme'
					});
				}
			});
			
			$('#zj-input-back-record-order').combobox({
				onSelect:function(oid){
					$("#zj-input-back-record-order-hidden").textbox("setValue",oid.coId);
				}
			});
		});

		function deleteBackRecord(brId){
			$.messager.confirm('提示', '确定要删除吗？', function(v) {
				if (v) {
					$.getJSON('deleteBr', {
						brId : brId
					}, function(obj) {
						if (obj.success) {
							$('#zj-back-record-all-dg').datagrid('reload');
						} else {
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
						}
					});
				}
			});
		}
		
		function editBackRecord(brId) {
			$("#zj-back-record-dialog").dialog({
				title : '编辑回款记录'
			});
			$("#zj-back-record-add-form").form('load',
					'getBackRecordById?brId=' + brId);
			$("#zj-back-record-form-cus").textbox({readonly:true})
			$("#zj-back-record-dialog").dialog("open");
		}
	</script>
	<div id="zj-back-record-tb">
		<a id="zj_btn_back_record_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加</a> <a
			id="zj_back_record_list_all" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	<table id="zj-back-record-all-dg"></table>
	<div id="zj-back-record-dialog" class="easyui-dialog"
		style="width: 455px; height: 470px;"
		data-options="iconCls:'icon-save',closed:true,resizable:true,modal:true,buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					$('#zj-back-record-add-form').form({
							url:'addBackRecord',
							method:'post',
						onSubmit:function(param){
							return $(this).form('validate');
						},
						success:function(v){
						var obj = eval('('+v+')');
							if(obj.success){
								$('#zj-back-record-all-dg').datagrid('reload');
							}else{
							$.messager.alert('提示', '操作失败,原因：' + obj.message);
							}
							$('#zj-back-record-dialog').dialog('close');
						}	
					}).submit();
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#zj-back-record-dialog').dialog('close');
				}
			}]">
		<form id="zj-back-record-add-form" method="post">
			<input  id="zj-back-recor-brid" type="hidden" class="easyui-textbox" name="brCoId">
			<div class="step">
				<input id="zj-back-record-form-cus" name="brCoName"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'选择客户',required:true,labelAlign:'right',label:' ',labelWidth:'90',width:320, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-back-record-form-cus').textbox('setValue', row.custName);
							$('#zj-back-record-form-cus').textbox('setText', row.custName);
							$('#zj-back-recor-brid').textbox('setValue',row.custId);
						});		
					}">
			</div>
			<input id="zj-input-back-record-order-hidden" class="easyui-textbox" type="hidden" name="coIdvo">
			<div class="step">
				<input id="zj-input-back-record-order" class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',required:true,labelAlign:'right',label:'订单',
					width:280, labelWidth:90"
					name="coThemeVo">
			</div>
			
			<div class="step">
				<select class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:true,label:'期次',
					width:280, labelWidth:90"
					name="brPeriod">
					<option disabled selected value=''></option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<option value="8">8</option>
					<option value="9">9</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
				</select>
			</div>
			<div class="step">
				<input class="easyui-datebox"
					data-options="required:true,labelAlign:'right',label:'回款日期',
					width:300, labelWidth:90"
					name="brTime">
			</div> 
			<div class="step">
				<input class="easyui-numberbox" name="brMoney"
					data-options="min:0,precision:2,labelAlign:'right',required:true,label:'金额',
							width:220, labelWidth:90">
			</div>
			<div class="step">
				<select class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:true,label:'付款方式',
					width:280, labelWidth:90"
					name="brPayWay">
					<option disabled selected value=''></option>
					<option value="支票">支票</option>
					<option value="现金">现金</option>
					<option value="邮政汇款">邮政汇款</option>
					<option value="网上银行">网上银行</option>
				</select>
			</div>
			<div class="step" style="margin-left: 30px;">
				已开发票<input style="margin-left: 20px;" value="是" name="brIfTicket"
					checked="checked" type="radio">是<input value="否"
					name="brIfTicket" type="radio">否<input value="无需开票"
					name="brIfTicket" type="radio">无需开票
			</div>
			<div class="step">
				<input id="zj-form-back-record-owner" name="brOwner"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'所有者', label:' ', labelWidth:'90', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-form-back-record-owner').textbox('setValue', row.custName);
							$('#zj-form-back-record-owner').textbox('setText', row.custName);
						});
					}">
			</div>
			<!-- <div class="step">
				<input class="easyui-textbox"
					data-options="multiline:true,required:false,labelAlign:'right',label:'备注',
					width:320,height:40,labelWidth:90"
					name="brRemarks">
			</div> -->
		</form>
	</div>
</body>
</html>